require_relative 'boot'

require 'rails/all'
require 'csv'
require 'sdoc'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Ajax
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    config.time_zone = 'Beijing'
    config.active_record.default_timezone = :local

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
    config.i18n.default_locale = "zh-CN"
    I18n.locale = "zh-CN"

    # 使用redis作为默认缓存
    redis_config = YAML.load_file(Rails.root.join('config', 'redis.yml'))[Rails.env]
    config.cache_store = :redis_store, "redis://#{redis_config['host']}:#{redis_config['port']}/0/#{Rails.env}_cache"
    config.active_job.queue_adapter = :sidekiq
    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
    config.i18n.default_locale = "zh-CN"
    # I18n.locale = "zh-CN"
    #push request
    config.action_cable.disable_request_forgery_protection = true
    # config.autoload_paths += %W(#{config.root}/lib)
    config.eager_load_paths << Rails.root.join('lib')

    # Do not swallow errors in after_commit/after_rollback callbacks.
    config.active_record.raise_in_transactional_callbacks = true

    # config.middleware.insert_before 0, "Rack::Cors", :debug => true, :logger => (-> { Rails.logger }) do
    #   allow do
    #     origins '*'
    #
    #     resource '/cors',
    #       :headers => :any,
    #       :methods => [:post],
    #       :credentials => true,
    #       :max_age => 0
    #
    #     resource '*',
    #       :headers => :any,
    #       :methods => [:get, :post, :delete, :put, :patch, :options, :head],
    #       :max_age => 0
    #   end
    # end
   end
end
